package com.Java.train.business.controller;

import com.Java.train.common.response.CommonResp;
import com.Java.train.business.entity.DTO.TrainCarriageDTO;
import com.Java.train.business.req.TrainCarriageQueryReq;
import com.Java.train.common.response.PageResp;
import com.Java.train.business.entity.TrainCarriage;
import com.Java.train.business.service.TrainCarriageService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;

/**
* @author luomoxingchen
* @since 2024-09-22
*/
@RestController
@RequestMapping("/admin/train-carriage")
public class TrainCarriageController {

    @Autowired
    private TrainCarriageService trainCarriageService;


    @GetMapping("/query-list")
    @ApiOperation("TrainCarriage查询全部")
    public CommonResp< PageResp<TrainCarriageDTO>> queryList(@Valid TrainCarriageQueryReq trainCarriageQueryReq){
        PageResp<TrainCarriageDTO> list = trainCarriageService.queryList(trainCarriageQueryReq);
        return new CommonResp<>(list);
    }

    @PostMapping("/save")
    @ApiOperation("TrainCarriage修改")
    public CommonResp<Object> update(@Valid @RequestBody TrainCarriage trainCarriage) {
        return trainCarriageService.modify(trainCarriage);
    }


    @DeleteMapping(value = "/delete/{ids}")
    @ApiOperation("TrainCarriage删除(单个条目)")
    public CommonResp<Object> remove(@NotBlank(message = "{required}") @PathVariable String ids) {
        return trainCarriageService.remove(ids);
    }
}
